package com.ruoyi.app.controller.project;

import com.ruoyi.app.business.project.ProjectSettleBusiness;
import com.ruoyi.app.config.annotation.OperationAuth;
import com.ruoyi.app.domain.project.settle.ProjectSettleDetail;
import com.ruoyi.app.domain.project.settle.ProjectSettleInfo;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.project.query.SettleQuery;
import com.ruoyi.service.user.enums.UserTypeEnum;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目结算管理
 *
 * @author Zane
 * @since 2025-10-10
 */
@RestController
@RequestMapping("/project/settle/")
public class ProjectSettleController {

  @Resource
  private ProjectSettleBusiness projectSettleBusiness;

  /**
   * 项目结算列表[项目方]
   */
  @OperationAuth(value = {UserTypeEnum.DEMANDER_USER})
  @PostMapping("/listForDemander")
  public TableDataInfo<ProjectSettleInfo> listForDemander(
      @Validated @RequestBody SettleQuery settleQuery) {
    CommonPageInfo<ProjectSettleInfo> projects =
        projectSettleBusiness.demanderListSettle(settleQuery);
    return CommonUtils.buildTableData(projects);
  }

  /**
   * 项目结算列表[平台方]
   */
  @OperationAuth(value = {UserTypeEnum.PLATFORM_USER})
  @PostMapping("/listForPlatform")
  public TableDataInfo<ProjectSettleInfo> listForPlatform(
      @Validated @RequestBody SettleQuery settleQuery) {
    CommonPageInfo<ProjectSettleInfo> projects =
        projectSettleBusiness.platformListSettle(settleQuery);
    return CommonUtils.buildTableData(projects);
  }

  /**
   * 结算明细
   *
   * @param id 结算单Id
   */
  @OperationAuth(value = {UserTypeEnum.DEMANDER_USER, UserTypeEnum.PLATFORM_USER})
  @PostMapping("/detail")
  public APIResult<ProjectSettleDetail> detail(@RequestParam("id") Long id) {
    ProjectSettleDetail detail = projectSettleBusiness.detailById(id);
    return APIResult.success(detail);
  }
}
